//递归组织树状结构方法
function recursionDataTree(dataList,pid){
    let resultList = [];    
    if (!dataList) return null; 
    for (const map of dataList) {
        let bmid_new = map["id"];
        let parentId = map["parent_id"];
        if(!pid) pid = 0;
        if (pid==parentId) {
            const data = map;
            data['showMenu'] = false;
            let childrenList = recursionDataTree(dataList, bmid_new);
            if (childrenList) data["children"]= childrenList;
            resultList.push(data);
        }

    }
    return resultList;
}

function formatData(date){
    if(!date) return '';
    let data = new Date(date);
    let year = (data.getFullYear()<10) ? '0'+data.getFullYear() : data.getFullYear();
    let month = (data.getMonth()<10) ? '0'+data.getMonth() : data.getMonth();
    let day = (data.getDate()<10) ? '0'+data.getDate() : data.getDate();
    let hour = (data.getHours()<10) ? '0'+data.getHours() : data.getHours();
    let min = (data.getMinutes()<10) ? '0'+data.getMinutes() : data.getMinutes();
    let secd =  (data.getSeconds()<10) ? '0'+data.getSeconds() : data.getSeconds();
    return year+'/'+month+'/'+day+" "+hour+":"+min+":"+secd;
}






module.exports = {
    recursionDataTree,
    formatData
}